%%数据库
-module(fun_db).
-include("common.hrl").

-export([install/0]).

install()->
	mnesia:stop(),
	mnesia:delete_schema([node()]),
	mnesia:create_schema([node()]),
	mnesia:start(),
	
	{atomic, ok} = mnesia:create_table(config, [{ram_copies, [node()]}, {attributes, record_info(fields, config)}]),
	{atomic, ok} = mnesia:create_table(sql_config, [{ram_copies, [node()]}, {attributes, record_info(fields, sql_config)}]),
	{atomic, ok} = mnesia:create_table(sql_key_static, [{ram_copies, [node()]}, {attributes, record_info(fields, sql_key_static)}]),
	
	{atomic, ok} = mnesia:create_table(ply, [{ram_copies, [node()]}, {attributes, record_info(fields, ply)}, {index, [name,aid]}]),
	{atomic, ok} = mnesia:create_table(off_ply, [{ram_copies, [node()]}, {attributes, record_info(fields, off_ply)}]),	
	{atomic, ok} = mnesia:create_table(room, [{ram_copies, [node()]}, {attributes, record_info(fields, room)}]),
	{atomic, ok} = mnesia:create_table(cache, [{ram_copies, [node()]}, {attributes, record_info(fields, cache)}]),
	
	{atomic, ok} = mnesia:create_table(account, [{ram_copies, [node()]}, {attributes, record_info(fields, account)}, {index, [acc_name,name]}]),
	{atomic, ok} = mnesia:create_table(acc_login_log, [{ram_copies, [node()]}, {attributes, record_info(fields, acc_login_log)}]),
	{atomic, ok} = mnesia:create_table(admin_log, [{ram_copies, [node()]}, {attributes, record_info(fields, admin_log)}]),
	{atomic, ok} = mnesia:create_table(game_log, [{ram_copies, [node()]}, {attributes, record_info(fields, game_log)}]),
	{atomic, ok} = mnesia:create_table(item, [{ram_copies, [node()]}, {attributes, record_info(fields, item)}, {index, [acc_id]}]),
	{atomic, ok} = mnesia:create_table(resource_log, [{ram_copies, [node()]}, {attributes, record_info(fields, resource_log)}]),
	{atomic, ok} = mnesia:create_table(task, [{ram_copies, [node()]}, {attributes, record_info(fields, task)}, {index, [acc_id]}]),
	
	{atomic, ok} = mnesia:create_table(group_info, [{ram_copies, [node()]}, {attributes, record_info(fields, group_info)}, {index, [create_aid]}]),
	{atomic, ok} = mnesia:create_table(group_members, [{ram_copies, [node()]}, {attributes, record_info(fields, group_members)}, {index, [accid]}]),
	mnesia:stop().